// This File is part of the "nyaqt" Project
// 
// Copyright  2009 sometmes@gmail.com
// All rights reserved
// 
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.



using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using nyaqt.Plugins;

namespace nyaqt.MsSqlPlugIn
{
    class ConnectionProperties : nyaqt.Plugins.IConnectionProperties
    {
        SqlConnection cn = null;

        public System.Data.IDbConnection Connection
        {
            get
            {
                return this.cn;
            }
            set
            {
                this.cn = value as SqlConnection;
            }
        }

        public string Server
        {
            get
            {
                return this.cn.DataSource;
            }
        }

        public string Database
        {
            get
            {
                return this.cn.Database;
            }
        }

        string userName = null;
        public string UserName
        {
            get
            {
                if (userName == null)
                {
                    SqlCommand cmd = new SqlCommand("select user_name()",this.cn);
                    userName = cmd.ExecuteScalar() as string;
                }
                return userName;
            }
        }

        public string ServerBrowseKey
        {
            get
            {
                return Server + "/" + UserName;
            }
        }

        public List<nyaqt.Plugins.DatabaseEntityInfo> GetDatabases()
        {
            List<DatabaseEntityInfo> ret = new List<DatabaseEntityInfo>();
            DatabaseEntityInfo e = new DatabaseEntityInfo();
            e.DatabaseName = "The method or operation is not implemented.";
            ret.Add(e);
            return ret;
        }

        public List<nyaqt.Plugins.DatabaseEntityInfo> GetDatabaseTables(string database)
        {
            List<DatabaseEntityInfo> ret = new List<DatabaseEntityInfo>();
            DatabaseEntityInfo e = new DatabaseEntityInfo();
            e.TableName = "The method or operation is not implemented.";
            ret.Add(e);
            return ret;
        }

        public List<nyaqt.Plugins.DatabaseEntityInfo> GetDatabaseViews(string database)
        {
            List<DatabaseEntityInfo> ret = new List<DatabaseEntityInfo>();
            DatabaseEntityInfo e = new DatabaseEntityInfo();
            e.TableName = "The method or operation is not implemented.";
            ret.Add(e);
            return ret;
        }

        public List<nyaqt.Plugins.DatabaseEntityInfo> GetDatabaseStoredProcedures(string database)
        {
            List<DatabaseEntityInfo> ret = new List<DatabaseEntityInfo>();
            DatabaseEntityInfo e = new DatabaseEntityInfo();
            e.TableName = "The method or operation is not implemented.";
            ret.Add(e);
            return ret;
        }

        public List<DatabaseEntityInfo> GetDatabaseSystemTables(string database)
        {
            List<DatabaseEntityInfo> ret = new List<DatabaseEntityInfo>();
            DatabaseEntityInfo e = new DatabaseEntityInfo();
            e.TableName = "The method or operation is not implemented.";
            ret.Add(e);
            return ret;
        }

        public List<DatabaseEntityInfo> GetDatabaseTableColumns(string database, string tableNamespace, string table)
        {
            List<DatabaseEntityInfo> ret = new List<DatabaseEntityInfo>();
            DatabaseEntityInfo e = new DatabaseEntityInfo();
            e.TableName = "The method or operation is not implemented.";
            ret.Add(e);
            return ret;
        }

        public List<DatabaseEntityInfo> GetDatabaseTableRelations(string database, string tableNamespace, string table)
        {
            List<DatabaseEntityInfo> ret = new List<DatabaseEntityInfo>();
            DatabaseEntityInfo e = new DatabaseEntityInfo();
            e.TableName = "The method or operation is not implemented.";
            ret.Add(e);
            return ret;
        }

        public List<DatabaseEntityInfo> GetDatabaseTableRelationColumns(string database, string tableNamespace, string table, string relatedTableNamespace, string relatedTable)
        {
            List<DatabaseEntityInfo> ret = new List<DatabaseEntityInfo>();
            DatabaseEntityInfo e = new DatabaseEntityInfo();
            e.TableName = "The method or operation is not implemented.";
            ret.Add(e);
            return ret;
        }

        public List<DatabaseEntityInfo> GetDatabaseStoredProcedureParameters(string database, string tableNamespace, string table)
        {
            List<DatabaseEntityInfo> ret = new List<DatabaseEntityInfo>();
            DatabaseEntityInfo e = new DatabaseEntityInfo();
            e.TableName = "The method or operation is not implemented.";
            ret.Add(e);
            return ret;
        }

        public string FormatSelectTopQuery(int top, DatabaseEntityInfo table, List<DatabaseEntityInfo> columns)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public string ConnectionStringPasswordKey
        {
            get { return "Password"; }
        }

        public event ConnectionMessageDelegate ConnectionMessage;

        public string FormatOwnException(Exception ex)
        {
            return "";
        }
    }
}
































